package com.macro.mall.portal.controller.klxx;

import com.macro.mall.model.UmsMember;
import com.macro.mall.portal.service.UmsMemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.BadCredentialsException;

import javax.annotation.Resource;

/**
 * @author xq
 * @description BaseController
 * @date 2024/2/23 15:21
 */
@Slf4j
public class BaseController {

    @Resource
    private UmsMemberService memberService;

    public UmsMember getCurrentMember() {
        try {
            UmsMember currentMember = memberService.getCurrentMember();
            if (currentMember == null) {
                throw new BadCredentialsException("未授权");
            }
            return currentMember;
        } catch (Exception e) {
            log.error("BaseController.getCurrentMember,{}", e.getMessage());
            throw new BadCredentialsException("未授权");
        }
    }

}
